package demo;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class TestMain {
    
    public static void test1()
    {
        System.out.println("test1...");
        Axe steelaxe = new SteelAxe();  
        Axe stoneaxe = new StoneAxe();  
        WoodCutter c1 = new WoodCutter();
        c1.setAxe(stoneaxe);       // 设值注入 通过set方法传参注入被调用的对象, 这里注入的是stoneaxe
        c1.useAxe();
        
        WoodCutter c2 = new WoodCutter(steelaxe); //构造注入 steelaxe
        c2.useAxe();


        ApplicationContext ctx = new ClassPathXmlApplicationContext("bean_lec01.xml");
        //设值注入 配置
        Person p1 = (Person)ctx.getBean("woodcutter01");
        p1.useAxe();
        //构造注入 配置
        Person p2 = (Person)ctx.getBean("woodcutter02");
        p1.useAxe();
    }
    public static void main(String[] args) {
        
        System.out.println("***My name is Zhao! This is My Code.***");
        test1();
        
    }
}